package com.vancouver.knows.service;

import android.os.Message;
import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import com.vancouver.knows.MainApplication;
import com.vancouver.knows.util.PhoConstants;

/**
 * Created by llf on 2017/4/12.
 */

public class InstanceIdService extends FirebaseInstanceIdService {

    public static final String TAG = InstanceIdService.class.getSimpleName();

    @Override
    public void onTokenRefresh() {
        super.onTokenRefresh();

        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.i(TAG, "Token: " + refreshedToken);
        //发送到服务端
        sendRegistrationToServer(refreshedToken);

    }

    private void sendRegistrationToServer(String token) {
        MainApplication imContext = (MainApplication) getApplication();
        Message msg = Message.obtain();
        msg.what = PhoConstants.FCM_STATUS_TOKEN;
        msg.obj = token;
        imContext.handleMobMessage(msg);
    }
}
